package hsl.study.controller;


import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Author: hsl
 * @CreateDate: 2025/8/4 9:51
 * @Version: 1.0
 */

@RestController
@RequestMapping("/embed2Vector")
public class Embed2VectorController {
    @Resource
    private VectorStore vectorStore;

    @GetMapping("/add")
    public void add() {
        List<Document> documentList = List.of(
                new Document("i study LLM"),
                new Document(" hsl  lhr ")
        );
        vectorStore.add(documentList);
    }

    @GetMapping("/get")
    public List getAll(@RequestParam(name = "msg") String msg) {
        SearchRequest searchRequest = SearchRequest.builder()
                .query(msg)
                .topK(2)
                .build();

        List<Document> documentList = vectorStore.similaritySearch(searchRequest);
        System.out.println("documentList = " + documentList);
        return documentList;

    }
}
